package com.hollysys.hollimsa.common.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;

/**
 *
 * @author wangyuxi
 * @param <T>
 */
@ApiModel(value = "返回说明")
@Data
public class AjaxObject<T> implements Serializable {

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;


	/**
     * 返回码
     */
    @ApiModelProperty(value = "返回码标识")
    private String code;
    /**
     * 消息内容
     */
    @ApiModelProperty(value = "返回消息内容")
    private String msg;

    /**
     * 请求返回的数据
     */
    @ApiModelProperty(value = "返回的数据信息")
    private T result;



    public static <T> AjaxObject<T> basicAjax(AjaxCodeEnum ajaxCodeEnum, T result) {
        AjaxObject<T> ajaxObject = new AjaxObject<>();
        ajaxObject.code = ajaxCodeEnum.getCode();
        ajaxObject.msg = ajaxCodeEnum.getName();
        ajaxObject.result = result;
        return ajaxObject;
    }


    public static <T> AjaxObject<T> customAjax(String code, String msg, T result) {
        AjaxObject<T> ajaxObject = new AjaxObject<>();
        ajaxObject.code = code;
        ajaxObject.msg = msg;
        ajaxObject.result = result;
        return ajaxObject;
    }

    public static <T> AjaxObject<T> customOk(String msg, T result) {
        AjaxObject<T> ajaxObject = new AjaxObject<>();
        ajaxObject.code = AjaxCodeEnum.OK.getCode();
        ajaxObject.msg = msg;
        ajaxObject.result = result;
        return ajaxObject;
    }

    public static <T> AjaxObject<T> customFail(String msg, T result) {
        AjaxObject<T> ajaxObject = new AjaxObject<>();
        ajaxObject.code = AjaxCodeEnum.FAIL.getCode();
        ajaxObject.msg = msg;
        ajaxObject.result = result;
        return ajaxObject;
    }

}
